<template>
	<view class="setting">
		<view class="information">
			<view class="title ml-20">基本信息</view>
			<u-field v-model="dataForm.contact" required label="联系人" input-align='right' placeholder="请输入联系人"></u-field>
			<u-field v-model="dataForm.phone" required label="手机号码" input-align='right' placeholder="请输入手机号码"></u-field>
			<u-field v-model="dataForm.custom_tel" label="客服电话" input-align='right' placeholder="请输入客服电话"></u-field>
			<u-field v-model="dataForm.address" label="商家地址" input-align='right' placeholder="请输入商家地址"></u-field>
		</view>
		<view class="information">
			<view class="title ml-20">审核设置</view>
			<view class="box ">
				<view class="ml-20 box-tit">是否锁粉</view>
				<view class=" box-swit">
					不锁<u-switch v-model="settingForm.lock_powder" size='40' style="margin: 0 20rpx;"></u-switch>锁
				</view>
			</view>
			<view class="box ">
				<view class="ml-20 box-tit">是否共享</view>
				<view class=" box-swit">
					不共享<u-switch v-model="settingForm.is_share" size='40' style="margin: 0 20rpx;"></u-switch>共享
				</view>
			</view>
			<view class="box ">
				<view class="ml-20 box-tit">分销是否审核</view>
				<view class=" box-swit">
					不审核<u-switch v-model="settingForm.examine" size='40' style="margin: 0 20rpx;"></u-switch>审核
				</view>
			</view>
			<view class="box ">
				<view class="ml-20 box-tit">佣金是否审核</view>
				<view class=" box-swit">
					不核销<u-switch v-model="settingForm.commission" size='40' style="margin: 0 20rpx;"></u-switch>核销
				</view>
			</view>
		</view>
		<view class="information">
			<view class="title ml-20">提现说明</view>
			<view class="box ">
				<view class="ml-20 box-tit">最低提现金额</view>
				<view class=" box-swit">
					<u-number-box v-model="settingForm.withdraw"></u-number-box>
				</view>
			</view>
			<view class=" box-swit">
				<u-field type="textarea" label="提现说明" maxlength='1000' input-align='right' :clearable='false'
					v-model="settingForm.withdraw_explain" placeholder="提现说明" style="position: relative;right: 8rpx;">
				</u-field>
			</view>
		</view>
		<view class="information">
			<view class="title ml-20">修改密码</view>
			<u-field v-model="passForm.oldpassword" password label="旧密码" input-align='right' placeholder="请输入旧密码">
			</u-field>
			<u-field v-model="passForm.newpassword" password label="新密码" input-align='right' placeholder="请输入新密码">
			</u-field>
			<u-field v-model="passForm.againnew" password label="再次输入" input-align='right' placeholder="请再输入"></u-field>
		</view>
		<view class="save" @click="submit">保存</view>
	</view>
</template>

<script>
	import {
		GetQueryDataList,
		adminPost,
		UpdateModifyData
	} from '@/common/http.request.js'
	export default {
		data() {
			return {
				dataForm: {
					contact: '',
					phone: '',
					custom_tel: '',
					address: ''
				},
				passForm: {
					oldpassword: '',
					newpassword: '',
					againnew: ''
				},
				settingForm: {}
			}
		},
		onLoad() {
			GetQueryDataList('b_business', 1, 1, {
				pk_id: this.$store.state.vuex_adminuser.pk_id
			},{setting:true,api:true}).then(res => {
				// console.log(res)
				this.dataForm = res.data[0]
			})
			GetQueryDataList('b_business_setup', 1, 1, {
				fk_business_id: this.$store.state.vuex_adminuser.pk_id
			},{setting:true,api:true}).then(res => {
				// console.log(res)
				this.settingForm = res.data[0]
				this.settingForm.lock_powder = this.settingForm.lock_powder == 1 ? false : true
				this.settingForm.is_share = this.settingForm.is_share == 1 ? true : false
				this.settingForm.examine = this.settingForm.examine == 1 ? false : true
				this.settingForm.commission = this.settingForm.commission == 1 ? false : true
			})
		},
		methods: {
			async submit() {
					let newpw = (await this.$adminPost('GetMD5Encryption',{password:this.passForm.newpassword})).data
					let oldpassword = (await this.$adminPost('GetMD5Encryption',{password:this.passForm.oldpassword})).data
					if (!(this.passForm.newpassword == this.passForm.againnew)) {
						return this.$toast('两次密码不一致')
					} else if ( oldpassword != this.dataForm.password){
						return this.$toast('旧密码不正确')
					}else if(this.passForm.newpassword.length<6&&this.passForm.newpassword || this.passForm.againnew.length<6&&this.passForm.againnew){
						return this.$toast('密码不能少于6位')
					}else if(newpw == this.dataForm.password){
						return this.$toast('新密码不能与旧密码相同')
					}else if(!this.dataForm.contact || this.dataForm.contact.trim() == ''){
						return this.$toast('联系人不能为空')
					}else if (!this.dataForm.phone|| this.dataForm.phone.trim() == ''){
						return this.$toast('手机号不能为空')
					}
				let data={
					contact:this.dataForm.contact,
					phone:this.dataForm.phone,
					custom_tel:this.dataForm.custom_tel,
					address:this.dataForm.address,
					withdraw:this.settingForm.withdraw,
					lock_powder:this.settingForm.lock_powder == false ?  1: 0,
					is_share: this.settingForm.is_share == true ? 1 : 0,
					examine: this.settingForm.examine == false ?  1: 0,
					commission:this.settingForm.commission == false ? 1 : 0,
					password:this.passForm.oldpassword,
					new_password:this.passForm.newpassword,
					withdraw_explain:this.settingForm.withdraw_explain,
					headerMethod:'json'
				}
				adminPost('SetBusinessSetup',{pk_id:this.dataForm.pk_id},data).then(res=>{
					if(this.passForm.oldpassword&&this.passForm.newpassword){
						this.$linkTo('/package/system/login')
						return
					}
					this.$u.vuex('vuex_adminuser', {...this.$store.state.vuex_adminuser,...this.dataForm});
					this.uniBack(1)
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f5f5f5;
	}
</style>

<style lang='scss' scoped>
	.setting {
		padding: 0 30rpx;

		.ml-20 {
			margin-left: 20rpx;
		}

		.information {
			width: 100%;
			background-color: #fff;
			border-radius: 20rpx;
			margin: 30rpx 0;
			padding: 20rpx;

			.title {
				font-weight: bold;
				font-size: 32rpx;
			}
		}

		.box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 0;

			.box-tit {}

			.box-swit {
				display: flex;
				align-items: center;
			}
		}

		.save {
			width: 100%;
			line-height: 80rpx;
			text-align: center;
			background-color: #49a3f1;
			color: #fff;
			border-radius: 20rpx;
			margin-bottom: 40rpx;
		}
	}
</style>
